package com.leyou.common.advice;


import com.leyou.common.exception.LyException;
import com.leyou.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice//拦截异常统一处理
public class CommonExceptionHadler {

    @ExceptionHandler(LyException.class)//统一处理某一类异常，从而能够减少代码重复率和复杂度
    public ResponseEntity<ExceptionResult> handeException(LyException e) {
        return ResponseEntity.status(e.getExceptionEnum().getCode()).body(new ExceptionResult(e.getExceptionEnum()));
    }

}
